package net.esj.basic.core.utils.jep;

import java.util.Set;

import net.esj.basic.utils.ClassUtils;

import com.singularsys.jep.ComponentSet;
import com.singularsys.jep.Jep;
import com.singularsys.jep.JepComponent;
import com.singularsys.jep.PostfixMathCommandI;
import com.singularsys.jep.functions.PostfixMathCommand;

public class MelonJep extends Jep {

	public MelonJep() {
		super();
		try {
			init();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
	}

	public MelonJep(ComponentSet arg0) {
		super(arg0);
		try {
			init();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
	}

	public MelonJep(JepComponent... arg0) {
		super(arg0);
		try {
			init();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
	}

	private void init() throws InstantiationException, IllegalAccessException{
		Set<Class<?>> classes =ClassUtils.getClasses(MelonJep.class.getPackage()) ;
		for(Class clazz : classes){
			if(PostfixMathCommand.class.isAssignableFrom(clazz)){
				addFunction(ClassUtils.transClassname2Beanname(clazz.getSimpleName()), (PostfixMathCommandI) clazz.newInstance());
			}
		}
		
	}
}
